Skip to content

Conversation

@vyavdoshenko
Copy link
Contributor

Implements the DD (Delete Documents) option for FT.DROPINDEX command.

Fixes: #5513

Comment on lines 1145 to 1146
// Collect document keys (if DD is set), drop index, and delete documents in single transaction
vector<vector<string>> shard_doc_keys(delete_docs ? shard_set->size() : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this inside the command, you can store the keys inside the transaction callback locally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 1151 to 1156
if (delete_docs) {
auto* index = es->search_indices()->GetIndex(idx_name);
if (index) {
shard_doc_keys[es->shard_id()] = index->GetAllKeys();
}
}
Copy link
Contributor

@dranikpg dranikpg Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to copy all the keys, you're gonna delete the index anyway. You can just return the DocKeyIndex by value from DropIndex() and empty it either with a helper function or by moving the ids_ map out of it directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

keys.reserve(ids_.size());

for (const auto& [key, id] : ids_) {
if (!key.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keys shouldn't be empty inside ids_ (only inside keys_), but see previous comment on that we don't need this function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@BorysTheDev
Copy link
Contributor

LGTM

@vyavdoshenko vyavdoshenko requested a review from dranikpg October 8, 2025 08:29
dranikpg
dranikpg previously approved these changes Oct 8, 2025
Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small style comments

// TODO: Handle optional DD param

// Parse optional DD (Delete Documents) parameter
bool delete_docs = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool delete_docs = args.size() > 1 && absl::EqualsIgnoreCase(args[1], "DD")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// Get const reference to document keys map (index will be destroyed after this scope)
const auto& doc_keys = index->key_index().GetDocKeysMap();

if (!doc_keys.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the if, you can just iterate over it right away

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's clean, simple and efficient👍🏻

@vyavdoshenko vyavdoshenko enabled auto-merge (squash) October 8, 2025 11:59
@vyavdoshenko vyavdoshenko merged commit ccdcfc3 into main Oct 8, 2025
10 checks passed
@vyavdoshenko vyavdoshenko deleted the bobik/drop_index_dd branch October 8, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support DD option the FT.DROPINDEX

4 participants